﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using ObjectTransposeApi;

namespace ObjectTransposeApiSystemTest.TestFixture
{
    [TestFixture]
    public class ToListSimpleTestFixture
    {
        public class SingleStructure
        {
            public string Value { get; set; }
        }

        [Test]
        public void NullTest()
        {
            List<SingleStructure> singleStructures = ObjectToList.Copy<SingleStructure>(null);

            // make sure the field was set
            Assert.AreEqual(singleStructures.Count, 0);
        }

        [Test]
        public void SingleTest()
        {
            var source = new
            {
                Value = "test"
            };

            List<SingleStructure> singleStructures = ObjectToList.Copy<SingleStructure>(source);

            // make sure the field was set
            Assert.AreEqual(singleStructures.Count, 1);
            Assert.AreEqual(singleStructures[0].Value, source.Value);
        }

        [Test]
        public void SingleTypeWrongTest()
        {
            var source = new
            {
                Value = 123
            };

            List<SingleStructure> singleStructures = ObjectToList.Copy<SingleStructure>(source);

            // make sure the field was set
            Assert.AreEqual(singleStructures.Count, 1);
            Assert.IsNull(singleStructures[0].Value);
        }

        [Test]
        public void SingleNameWrongTest()
        {
            var source = new
            {
                ValueOne = "test"
            };

            List<SingleStructure> singleStructures = ObjectToList.Copy<SingleStructure>(source);

            // make sure the field was set
            Assert.AreEqual(singleStructures.Count, 1);
            Assert.IsNull(singleStructures[0].Value);
        }

        [Test]
        public void SingleCollectionTest()
        {
            var sourceOne = new
            {
                Value = "test1"
            };

            var sourceTwo = new
            {
                Value = "test2"
            };

            var sourceThree = new
            {
                Value = "test3"
            };

            List<SingleStructure> singleStructures = ObjectToList.Copy<SingleStructure>(
                new object[] {sourceOne, sourceTwo, sourceThree});

            // make sure the field was set
            Assert.AreEqual(singleStructures.Count, 3);
            Assert.AreEqual(singleStructures[0].Value, sourceOne.Value);
            Assert.AreEqual(singleStructures[1].Value, sourceTwo.Value);
            Assert.AreEqual(singleStructures[2].Value, sourceThree.Value);
        }
    }
}
